package com.wuzhen.wzzt.controller;

import com.wuzhen.wzzt.core.ret.RetResponse;
import com.wuzhen.wzzt.core.ret.RetResult;
import com.wuzhen.wzzt.model.BannerInfo;
import com.wuzhen.wzzt.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * 报名接口
* @Description: BannerController
* @author zhengzheng
* @date 2022年4月1日 11:28
*/
@RestController
@RequestMapping("/banner")
@Api(tags = {"管理中心banner相关接口"}, description = "BannerController", position=2)
public class BannerController {

    private static Logger logger = LoggerFactory.getLogger(BannerController.class);

    @Value("${root.pic.url}")
    private String rootPicUrl;

    @Resource
    private BannerService bannerService;

    @PostMapping("/list")
    @ApiOperation(value = "banner列表", notes = "查询正常状态的banner列表")
    public RetResult<List<BannerInfo>> list() throws Exception {
        List<BannerInfo> list = bannerService.selectList();
        list.forEach(item->{
            this.setLpValue(item);
        });
        logger.info("banner列表查询返回记录条数：{}条",list.size());
        return RetResponse.makeOKRsp(list);
    }


    private void setLpValue(BannerInfo bannerInfo){
        if(bannerInfo!=null){
            if (bannerInfo.getBannerPicUrl()!=null&&!"".equals(bannerInfo.getBannerPicUrl())){
                    bannerInfo.setBannerPicUrl(rootPicUrl+"/ba/"+bannerInfo.getBannerPicUrl());
                }
            }
        }

}